package com.ruoyi.mng.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mng.mapper.HzCardOrderMapper;
import com.ruoyi.mng.domain.HzCardOrder;
import com.ruoyi.mng.service.IHzCardOrderService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 卡风险状态验证订单Service业务层处理
 *
 * @author Qiang
 * @date 2023-04-23
 */
@Service
public class HzCardOrderServiceImpl implements IHzCardOrderService {
    @Autowired
    private HzCardOrderMapper hzCardOrderMapper;
    @Resource
    private HzMerMerchantServiceImpl hzMerMerchantService;

    /**
     * 查询卡风险状态验证订单
     *
     * @param orderId 卡风险状态验证订单主键
     * @return 卡风险状态验证订单
     */
    @Override
    public HzCardOrder selectHzCardOrderByOrderId(Long orderId) {
        HzCardOrder hzCardOrder = hzCardOrderMapper.selectHzCardOrderByOrderId(orderId);
        hzCardOrder.setExtend_createTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, hzCardOrder.getCreateTime()));
        hzCardOrder.setExtend_merchantName(hzMerMerchantService.selectHzMerMerchantByMerchantId(hzCardOrder.getMerchantId()).getMerchantShortName());
        return hzCardOrder;
    }

    /**
     * 查询卡风险状态验证订单列表
     *
     * @param hzCardOrder 卡风险状态验证订单
     * @return 卡风险状态验证订单
     */
    @Override
    public List<HzCardOrder> selectHzCardOrderList(HzCardOrder hzCardOrder) {
        List<HzCardOrder> cardOrderList = hzCardOrderMapper.selectHzCardOrderList(hzCardOrder);
        cardOrderList.forEach((po) -> {
            po.setExtend_createTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, po.getCreateTime()));
            po.setExtend_merchantName(hzMerMerchantService.selectHzMerMerchantByMerchantId(po.getMerchantId()).getMerchantShortName());
        });
        return cardOrderList;
    }

    /**
     * 新增卡风险状态验证订单
     *
     * @param hzCardOrder 卡风险状态验证订单
     * @return 结果
     */
    @Override
    public int insertHzCardOrder(HzCardOrder hzCardOrder) {
        hzCardOrder.setCreateTime(DateUtils.getNowDate());
        return hzCardOrderMapper.insertHzCardOrder(hzCardOrder);
    }

    /**
     * 修改卡风险状态验证订单
     *
     * @param hzCardOrder 卡风险状态验证订单
     * @return 结果
     */
    @Override
    public int updateHzCardOrder(HzCardOrder hzCardOrder) {
        hzCardOrder.setUpdateTime(DateUtils.getNowDate());
        return hzCardOrderMapper.updateHzCardOrder(hzCardOrder);
    }

    /**
     * 批量删除卡风险状态验证订单
     *
     * @param orderIds 需要删除的卡风险状态验证订单主键
     * @return 结果
     */
    @Override
    public int deleteHzCardOrderByOrderIds(String orderIds) {
        return hzCardOrderMapper.deleteHzCardOrderByOrderIds(Convert.toStrArray(orderIds));
    }

    /**
     * 删除卡风险状态验证订单信息
     *
     * @param orderId 卡风险状态验证订单主键
     * @return 结果
     */
    @Override
    public int deleteHzCardOrderByOrderId(Long orderId) {
        return hzCardOrderMapper.deleteHzCardOrderByOrderId(orderId);
    }
}
